import Vue from 'vue'
const focus = Vue.directive('customLoading', {
  update: function(el, value) {
    if (value.value) {
      // console.log(el)
      const canPush = el.getElementsByClassName('customLoading')
      if (canPush.length !== 0) {
        return
      }
      el.style.position = 'relative'
      const para = document.createElement('div')
      const i_son = document.createElement('img')
      para.setAttribute('class', 'customLoading')
      i_son.setAttribute('class', 'refleash')
      i_son.src = '/loading.png'
      para.appendChild(i_son)
      el.appendChild(para)
    } else {
      for (var i = 0; i < el.childNodes.length; i++) {
        if (el.childNodes[i].className === 'customLoading') {
          const childNodes = el.getElementsByClassName('customLoading')[0]
          el.removeChild(childNodes)
          break
        }
      }
    }
  }
})
export default focus
